package cn.rongdao.jrkabao.ui.information.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRImageLoad;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.information.apply.ApplyInfoBean;
import cn.rongdao.jrkabao.constant.InfoConstant;
import cn.rongdao.jrkabao.ui.information.listener.OnItemActionListener;


/**
 * Created by jiangyongxing on 2016/7/21.
 * 描述：
 */
public class ApplyNeedInfoAdapter extends RecyclerView.Adapter<ApplyNeedInfoAdapter.ApplyNeedInfoViewHolder> {

    private List<ApplyInfoBean.MustListEntity> list;
    private OnItemActionListener mOnItemActionListener;
    private Context mContext;

    public ApplyNeedInfoAdapter(Context context, List<ApplyInfoBean.MustListEntity> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public ApplyNeedInfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_apply_need_info, parent, false);
        ApplyNeedInfoViewHolder holder = new ApplyNeedInfoViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ApplyNeedInfoViewHolder holder, final int position) {
        String code = list.get(position).getCode();
        holder.itemWarning.setVisibility(View.INVISIBLE);
        holder.itemName.setText(list.get(position).getCn());
        holder.itemStatus.setText(list.get(position).getMsg());
        holder.itemWarning.setVisibility(list.get(position).getStatus() == 2 ? View.VISIBLE : View.INVISIBLE);

        holder.itemStatus.setTextColor(getStatusColor(list.get(position).getStatus()));
        FRImageLoad.loadImage(list.get(position).getLogo(), holder.itemIcon);
        if (list.get(position).getJump_type() == 1) {
            holder.itemRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemActionListener != null) {
                        mOnItemActionListener.onItemClickWithUrl(list.get(position).getStatus(), list.get(position).getJump_url(), list.get(position).getCode());
                    }
                }
            });
            return;
        }
        switch (code) {
            case InfoConstant.IDENTITY_INFO://身份信息
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onIdentityInfoClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.BASIC_INFO://基本资料
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onBasicInfoClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.CREDIT_VERIFY://信用卡
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onCreditVerifyClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.DEPOSIT_CARD://储蓄卡
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onDepositCardClick(list.get(position).getStatus());
                        }
                    }
                });

                break;
            case InfoConstant.EC_VERIFY://电商
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onECVerifyClick(list.get(position).getStatus());
                        }
                    }
                });

                break;
            case InfoConstant.IDENTITY_PIC://身份证照骗
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onIdentityPicClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.OPERATOR_VERIFY://手机号验证
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onOperatorVerifyClick(list.get(position).getStatus());
                        }
                    }
                });


                break;
            case InfoConstant.PERSONAL_CREDIT://个人征信
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onPersonalCreditClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.PUBLIC_ACCUMULATION_FUND://公积金
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null) {
                            mOnItemActionListener.onPublicAccumulationFundClick(list.get(position).getStatus());
                        }
                    }
                });
                break;
            case InfoConstant.ZHIMA://芝麻信用
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null)
                            mOnItemActionListener.onZhimaClick(list.get(position).getStatus());
                    }
                });

                break;
            case InfoConstant.JD_VERIFY://京东
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null)
                            mOnItemActionListener.onJingdongClick(list.get(position).getStatus());
                    }
                });

                break;
            case InfoConstant.OTHER_FILM_PROFILE://资产证明
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null)
                            mOnItemActionListener.onOtherFilmprofileClick(list.get(position).getStatus());
                    }
                });
                break;
            case InfoConstant.ALIPAY://资产证明
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null)
                            mOnItemActionListener.onAlipayClick(list.get(position).getStatus());
                    }
                });
                break;
            case InfoConstant.SECURITY_VERIFY://社保
                holder.itemRl.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnItemActionListener != null)
                            mOnItemActionListener.onSecurityVerifyClick(list.get(position).getStatus());
                    }
                });
                break;


        }
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public void setOnItemActionListener(OnItemActionListener onItemActionListener) {
        this.mOnItemActionListener = onItemActionListener;
    }

    class ApplyNeedInfoViewHolder extends RecyclerView.ViewHolder {
        TextView itemName;
        TextView itemStatus;
        ImageView itemIcon;
        ImageView itemWarning;
        RelativeLayout itemRl;

        public ApplyNeedInfoViewHolder(View layout) {
            super(layout);
            itemName = (TextView) layout.findViewById(R.id.item_apply_need_info_name);
            itemStatus = (TextView) layout.findViewById(R.id.item_apply_need_info_status);
            itemRl = (RelativeLayout) layout.findViewById(R.id.item_apply_need_info_rl);
            itemIcon = (ImageView) layout.findViewById(R.id.item_apply_need_info_icon);
            itemWarning = (ImageView) layout.findViewById(R.id.item_apply_need_info_warning);
        }
    }


    private int getStatusColor(int status) {
        int data = R.color.c153153153;
        switch (status) {
            case -1:
            case 1:
                data = R.color.c153153153;
                break;
            case 0:
                data = R.color.c515151;
                break;
            case 2:
                data = R.color.colorPrimary;
                break;

        }
        return ContextCompat.getColor(mContext, data);

    }
}